// loan/housingLoan/housingLoan.js
const loanUtil = require("../../../../utils/loanUtil");
// 贷款年限
let year = 30;
// 贷款总额
let loanTotal;
const utils = require("../../../../utils/util");
let toggleCollection = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    year: "0", // 贷款年限
    loanTotal: "0", // 贷款总额
    yearInterestRate: "0", // 年利率
    monthMoney: "", // 月供
    detailList: [], // 分期详情
    totalInterest: "", // 累计利息
    totalRepayment: "", // 累计还款总额
    firstMonth: "0.00", // 首月月供
    scroll: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {    //  收藏组件参数
    toggleCollection = true;
    // utils.colleation(this, "公积金计算器");
    let curPages = getCurrentPages();
    let length = curPages.length;
    if (options.year && options.loanTotal && options.type) {
      let year = options.year;
      let loanTotal = parseFloat(options.loanTotal) * 10000;
      this.setData({
        year,
        loanTotal: options.loanTotal,
      });
      const methods = new loanUtil.LoanUtil("sz", this, year, loanTotal);
      if (options.type === "0")
        // 等额本金
        methods.equivalentPrincipal();
      else if (options.type === "1")
        // 等额本息
        methods.equivalentPrincipalAndInterest();
    }
  },
  onPageScroll() {
    if (toggleCollection) {
      this.setData({
        scroll: true,
      });
      toggleCollection = false;
    }

  },
  closeCollection() {
    toggleCollection = false;
  },
  openCollection() {
    toggleCollection = true;
  }
})